package com.gpl.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.gpl.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.gpl.domain.Car;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 车辆Controller
 * 
 * @author luna
 * @date 2023-05-22
 */
@RestController
@RequestMapping("/car")
@CrossOrigin
public class CarController extends BaseController
{
    @Autowired
    private ICarService carService;

    /**
     * 查询车辆列表
     */
    @RequiresPermissions("gpl:car:list")
    @GetMapping("/list")
    public TableDataInfo list(Car car)
    {
        startPage();
        List<Car> list = carService.selectCarList(car);
        return getDataTable(list);
    }

    /**
     * 导出车辆列表
     */
    @RequiresPermissions("gpl:car:export")
    @Log(title = "车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Car car)
    {
        List<Car> list = carService.selectCarList(car);
        ExcelUtil<Car> util = new ExcelUtil<Car>(Car.class);
        util.exportExcel(response, list, "车辆数据");
    }

    /**
     * 获取车辆详细信息
     */
    @RequiresPermissions("gpl:car:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(carService.selectCarById(id));
    }

    /**
     * 新增车辆
     */
    @RequiresPermissions("gpl:car:add")
    @Log(title = "车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Car car)
    {
        return toAjax(carService.insertCar(car));
    }

    /**
     * 修改车辆
     */
    @RequiresPermissions("gpl:car:edit")
    @Log(title = "车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Car car)
    {
        return toAjax(carService.updateCar(car));
    }

    /**
     * 删除车辆
     */
    @RequiresPermissions("gpl:car:remove")
    @Log(title = "车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)

    {
        return toAjax(carService.deleteCarByIds(ids));
    }

    @Autowired
    private ICellService cellService;
    /**
     * 查询电池表
     * @return
     */
    @GetMapping("/selectCell")
    public AjaxResult selectCell(){
        return AjaxResult.success(cellService.selectCell());
    }

    @Autowired
    private ITypeService typeService;
    /**
     * 查询车联类型表
     * @return
     */
    @GetMapping("/selectType")
    public AjaxResult selectType(){
        return AjaxResult.success(typeService.selectType());
    }


    @Autowired
    private IImitatePositionService iImitatePositionService;
    /**
     * 查询电子围栏表
     * @return
     */
    @GetMapping("/selectImitate")
    public AjaxResult selectImitate(){
        return AjaxResult.success(iImitatePositionService.selectImitate());
    }


    @Autowired
    private ITbStateService stateService;
    /**
     * 查询车辆状态表
     * @return
     */
    @GetMapping("/selectState")
    public AjaxResult selectState(){
        return AjaxResult.success(stateService.selectState());
    }


    @Autowired
    private IMachineService machineService;
    /**
     * 查询电机表
     * @return
     */
    @GetMapping("/selectMachine")
    public AjaxResult selectMachine(){
        return AjaxResult.success(machineService.selectMachine());
    }


    @Autowired
    private IBreakService breakService;
    /**
     * 查询故障类型表
     * @return
     */
    @GetMapping("/selectBreak")
    public AjaxResult selectBreak(){
        return AjaxResult.success(breakService.selectBreak());
    }






}
